package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.admin.service.FacilityInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * projectName: com.atguigu.lease.web.admin.controller.apartment
 *
 * @author: wangs
 * description:
 */

@Tag(name = "配套管理")
@RequestMapping("/admin/facility")
@RestController
public class FacilityController {

    @Autowired
    private FacilityInfoService facilityService;

    @GetMapping("list")
    @Operation(summary = "[根据类型]查询配套信息列表")
//    public Result list(){
//        List<FacilityInfo> facilityInfoList = facilityService.list();
//        return Result.ok(facilityInfoList);
//    }
    public Result<List<FacilityInfo>> list(@RequestParam(required = false)ItemType type){
        // 创建 LambdaQueryWrapper 对象
        LambdaQueryWrapper<FacilityInfo> facilityInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        // 封装查询条件
        facilityInfoLambdaQueryWrapper.eq(type != null, FacilityInfo::getType,type);
        // 调用带条件的查询
        List<FacilityInfo> facilityInfoList = facilityService.list(facilityInfoLambdaQueryWrapper);
        return Result.ok(facilityInfoList);
    }


    @PostMapping("saveOrUpdate")
    @Operation(summary = "新增或修改配套信息")
    public Result saveOrUpdate(@RequestBody FacilityInfo facilityInfo){
        facilityService.saveOrUpdate(facilityInfo);
        return Result.ok();
    }

    @DeleteMapping("deleteById")
    @Operation(summary = "根据id删除标签信息")
    public Result deleteById(@RequestParam Long id){
        facilityService.removeById(id);
        return Result.ok();
    }

}
